﻿namespace Vin.Tool.Core.DateTimeCategory;

public static partial class Extension
{
    /// <summary>
    /// 时间转时间戳（毫秒级）
    /// </summary>
    /// <param name="date">当前日期</param>
    /// <param name="isMs">默认毫秒</param>
    /// <returns></returns>
    public static long ToTimestamp(this DateTime date, bool isMs = true) => isMs
        ? TimestampTool.ConvertToTimestamp(date)
        : TimestampTool.ConvertToTimestampSeconds(date);

    public static long ToTimestamp(this DateTime? date, bool isMs = true) => date.HasValue
        ? isMs
            ? TimestampTool.ConvertToTimestamp(date.Value)
            : TimestampTool.ConvertToTimestampSeconds(date.Value)
        : 0;
}